import { createRouter, createWebHashHistory, createWebHistory } from 'vue-router'
import {fn} from '../utils/recurrence'
const routes = [

  
  {// 登陆
    path: '/login',
    name: 'Login',
    component: () => import('../views/Login.vue'),
  },
 
  { // 路由导航
    path: '/admin',
    name: 'admin',
    component: () => import('../views/Admin.vue'),
    children:[
       {
    path: '/goods',
    name: 'goods',
    component: () => import('../views/list/goods.vue'),
  },
    ]
  },
  //以下为测试页面
  {
    path: '/about',
    name: 'About',
    component: () => import(/* webpackChunkName: "About" */ '../views/About.vue')
  },
  {
    path: '/test',//vue3基本语法演示
    name: 'Test',
    component: () => import(/* webpackChunkName: "Test" */ '../views/Test.vue')
  },
  //根目录,到登录页面
  {
    path: '/',
    redirect: '/login'
  },
]


const router = createRouter({
  history: createWebHashHistory(), // hash模式：createWebHashHistory，history模式：createWebHistory
  routes
})
function dynami(){
  let token = localStorage.getItem('token') //取token
  let list =JSON.parse(localStorage.getItem('menuList')) //取左侧菜单数据
  if(token&&list){ //判断有没有拿到token和菜单数据
    let newlist = fn(list) //调用声明递归的方法
    console.log(newlist);
    // console.log(newlist,'牛啊');
    newlist.forEach(item=>{
      router.addRoute('admin',item)
    })
  }
}
dynami()
export default router
